import pandas as pd
import yaml
from pandas import DataFrame
from yaml import SafeLoader

from datareport.api.DataSource import DataSource
from datareport.api.annotation.Font import Font
from datareport.api.enum.ColorEnum import ColorEnum
from datareport.impl.paragraph.base.BaseParagraph import BaseParagraph
from datareport.api.annotation.Style import style
from datareport.api.enum.ParagraphStyleEnum import ParagraphStyleEnum


@style()
class YueChu_GongShiQingKuang_23(BaseParagraph):
    """
    月初公示
    """

    def __init__(self):
        super().__init__()
        self.text = '''1、月初公示: '''.format(' ','')
        self.tables: [DataFrame]=[]
        self.fonts=[
            Font(text=self.text)
        ]
        self.sort = 14
        self.section = 4

    def plot(self, df, plt):
        pass

    def getData(self, result):
        pass

    def start(self, conn, year, plt):

        df=pd.read_sql('''select partyOrgName '二级党组织',count(1) '场次' from(
        select partyOrgName
        from t_meetinginfo 
        where completeStatus='通过' and isPlan=1 and year(startTime)={}
        )new group by partyOrgName
        '''.format(year),con=conn)
        self.tables.append(df)


if __name__ == '__main__':
    with open('D:\work\sanhuiyike\datareport\config.yaml', encoding='utf-8') as f:
        data = yaml.load(f, Loader=SafeLoader)
    con = DataSource(data['datasource']).conn
    YueChu_GongShiQingKuang_23().start(con, 2023, '')

